﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace LIMS.SqlServerDAL
{
    /// <summary>
    /// 用户登录服务类
    /// By:田玉粮
    /// 2013.3.5
    /// </summary>
    public class LoginService : LIMS.IDAL.ILogin
    {
        LIMSDataContext limsDB = new LIMSDataContext();

        #region 检测用户ID
        /// <summary>
        /// 检测指定的教师的ID是否存在
        /// </summary>
        /// <param name="admin"></param>
        /// <returns>返回true表示该教师的ID已存在</returns>
        public Boolean Exists(LIMS.Model.Teachers teacher)
        {
            return limsDB.TB_teacher.Where(w => w.teacherId == teacher.teacherID).Select(s => s).Count() > 0;
        }

        /// <summary>
        /// 检测指定的管理员的ID是否存在
        /// </summary>
        /// <param name="admin"></param>
        /// <returns>返回true表示该管理员用户ID已存在</returns>
        public Boolean Exists(LIMS.Model.Admins admin)
        {
            return limsDB.TB_admin.Where(w => w.mesAdminId == admin.adminID).Select(s => s).Count() > 0 ;
        }

        /// <summary>
        /// 检测指定的学生的ID是否存在
        /// </summary>
        /// <param name="admin"></param>
        /// <returns>返回true表示该学生的ID已存在</returns>
        public Boolean Exists(LIMS.Model.Students student)
        {
            return limsDB.TB_Student.Where(w => w.stuNo == student.stuNo).Select(s => s).Count() > 0;
        }

        #endregion

        #region 登录

        /// <summary>
        /// 教师登录
        /// </summary>
        /// <param name="teacher"></param>
        /// <returns></returns>
        public Boolean UserLogin(LIMS.Model.Teachers tea)
        {
            return limsDB.TB_teacher.Where(t => t.teacherId == tea.teacherID && t.teacherPwd == tea.teacherPwd).Count() > 0;
        }

        public Boolean UserLogin(LIMS.Model.Students stu)
        {
            return limsDB.TB_Student.Where(s => s.stuNo == stu.stuNo && s.stuPwd == stu.stuPwd).Count() > 0;
        }

        public Boolean UserLogin(LIMS.Model.Admins adm)
        {
            return limsDB.TB_admin.Where(a => a.mesAdminId == adm.adminID && a.adminPwd == adm.adminPwd).Select(s => s).Count() > 0;
        }

        #endregion

        #region 注销
        /// <summary>
        /// 管理员注销，注销成功返回true
        /// </summary>
        /// <param name="admin"></param>
        /// <returns></returns>
        public bool UserLoginOut(LIMS.Model.Admins admin)
        {
            admin.adminID = string.Empty;
            return true;
        }

        /// <summary>
        /// 学生注销
        /// </summary>
        /// <param name="student"></param>
        /// <returns></returns>
        public bool UserLoginOut(LIMS.Model.Students student)
        {
            return false;
        }
        /// <summary>
        /// 教师注销
        /// </summary>
        /// <param name="teacher"></param>
        /// <returns></returns>
        public bool UserLoginOut(LIMS.Model.Teachers teacher)
        {
            return false;
        }
        #endregion




    }
}
